fix(chat): preserve attachments and dynamic variables when sending to a new chat (#292064)#310972
fix(chat): preserve attachments and dynamic variables when sending to a new chat (#292064)#310972maruthang wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug (#292064) where sending the current chat input to a new chat via Ctrl+Shift+Enter dropped attachments (#file:..., Changes) and dynamic-variable decorations (#changes). Previously SendToNewChatAction.run() only captured the plain input text, and clearChatSessionPreservingType wiped the attachmentModel and ChatDynamicVariableModel, so the re-sent text lost its context.
The fix captures the attachments and dynamic variables before clearing, then restores the input text via setInput, re-adds attachments through attachmentModel.addContext(...), re-adds dynamic variables through restoredDynamicVariableModel.addReference(...), and finally submits with acceptInput(undefined, { storeToHistory: true }) so the fresh input plus restored context flows through the normal submit path.
Changes:
- Capture
attachmentModel.attachmentsandChatDynamicVariableModel.variablesbefore the session clear, and restore them afterward before submitting. - Switch the final submit from
acceptInput(inputBeforeClear, …)tosetInput(...)+acceptInput(undefined, …)so restored context is included. - Add a
SendToNewChatActionunit-test suite verifying attachments and dynamic variables persist through the action and that the restore happens after the clear.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/vs/workbench/contrib/chat/browser/actions/chatExecuteActions.ts |
Captures and restores attachments and dynamic variables around the session clear so #changes/#file: context survives sending to a new chat. |
src/vs/workbench/contrib/chat/test/browser/actions/chatExecuteActions.test.ts |
Adds a SendToNewChatAction suite with a mock widget asserting restored input/attachments/variables and correct re-add ordering after clear. |
What — Sending the current input to a new chat (Ctrl+Shift+Enter) now carries attachments (
#file:..., Changes, etc.) and dynamic-variable decorations (#changes) over to the new session instead of dropping them on the floor.Why —
SendToNewChatAction.run()only captured the input as a plain text string. The subsequentclearChatSessionPreservingTypewipedattachmentModelandChatDynamicVariableModel, soacceptInput(inputBeforeClear)re-sent the text without its context.#changescame through as raw text with no Changes chip;#file:...lost its file attachment (#292064).How — Capture
widget.attachmentModel.attachmentsandChatDynamicVariableModel.variablesbefore the clear. After the clear,setInput(...)the text, then re-add both sets viaattachmentModel.addContext(...)andrestoredDynamicVariableModel.addReference(...). FinallyacceptInput(undefined, { storeToHistory: true })so the fresh input + restored context flows through the normal submit path.Test plan — New
SendToNewChatActionsuite: (1) attachments added before the action persist through toacceptInput; (2) dynamic variable references (e.g.#changes) persist through toacceptInput. Manual per the issue: typereview #changes, press Ctrl+Shift+Enter, verify the Changes chip + variable decoration appear in the new session.Fixes #292064